package com.knight.study.patterns.tujie.memento;

/**
 * @Author knight
 * @Date 2024/9/12 15:09
 */

public class MementoMains {
    public static void main(String[] args) {
        Gamer gamer = new Gamer(100);
        Memento memento = gamer.createMemento();
        for (int i = 0; i < 100; i++) {
            System.out.println("==== " + i);
            System.out.println("当前状态：" + gamer);
            gamer.bet();
            System.out.println("money:" + gamer.getMoney());
            if (gamer.getMoney() > memento.money) {
                System.out.println("(金额增加，因此保存)");
            } else if (gamer.getMoney() < memento.getMoney() / 2) {
                System.out.println("(金额减少，恢复)");
                gamer.restoreMemento(memento);
            }
            try {
                Thread.sleep(1000);
            } catch (Exception e) {
                e.printStackTrace();
            }
            System.out.println("");
        }
    }
}
